/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package marsaMaroc.dao;
 
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query; 
import marsaMaroc.model.Compte;

/**
 *
 * @author Administrateur
 */
public class LoginDAO{

    EntityManagerFactory emf = Persistence.createEntityManagerFactory("Marsa-MarocPU") ;
    EntityManager em;
    
    Compte compte;
    public Compte login(String nomUser, String passwordUser) { 
        em = emf.createEntityManager();
        Query q = em.createQuery("SELECT c FROM Compte c where c.nomUser='"+nomUser+"' AND c.passwordUser ='"+passwordUser+"'");
        System.out.println("taille liste "+q.getResultList().size());
        if(q.getResultList().size() > 0){
            compte = (Compte)q.getSingleResult();
            
            return compte;
        } 
        return null;
         
             
    }

     
}
